@extends('frontend/layouts/bootstrap')

@section('content')
<div>
    <span style="font-size: 31.5px;  line-height: 60px;  margin: 10px 0;  font-family: inherit;  font-weight: bold;  color: inherit;  text-rendering: optimizelegibility;  -webkit-margin-before: 0.83em;  -webkit-margin-after: 0.83em;  -webkit-margin-start: 0px;  -webkit-margin-end: 0px;"> Create new MoneyExchange</span>
    {{ link_to_route('car_balance.money_exchange.index', 'Back MoneyExchange list', null, array('class' => 'btn btn-info', 'style' => 'float: right; margin: 20px 0 10px 0;')) }}
</div>

<div class="row-fluid">
    {{ Form::open(array('route' => 'car_balance.money_exchange.create', 'class' => 'form-horizontal')) }}

    <div  class="control-group {{ $errors->first('recieve_date', ' error') }}">
        <label class="control-label" for="recieve_date">Recieve Date</label>
        <div class="controls">
            <input class="datepicker" placeholder="Recieve Date" title="Recieve Date" name="recieve_date" type="text" value="{{ Input::old('recieve_date') }}">
            {{ $errors->first('recieve_date', '<span class="help-inline">:message</span>') }}
        </div>
    </div>
    <div class="control-group {{ $errors->first('customer_id', ' error') }}">
        <label class="control-label">Customer</label>
        <div class="controls">
            {{ Form::select('customer_id', $customer_list, '', array('data-placeholder' => 'Customer', 'class' => 'chosen span6', 'name' => 'customer_id')) }}
            {{ $errors->first('customer_id', '<span class="help-inline">:message</span>') }}
        </div>
    </div>
    <div  class="control-group {{ $errors->first('recieve_date', ' error') }}">
        <label class="control-label" for="recieve_date">Мөнгөний нэгж</label>
        <div class="controls">
            <input style="margin: 5px;" type="radio" name="exchange_type" value="1" class="radio" id="exchange_type1">MNT
            <input style="margin: 5px;" type="radio" name="exchange_type" value="2" class="radio" id="exchange_type2">JPY
        </div>
    </div>
    <div  class="control-group {{ $errors->first('amount_tugrug', ' error') }}">
        <label class="control-label" for="amount_tugrug">Amount Tugrug</label>
        <div class="controls">
            <input id="amount_tugrug" class="tugrug" placeholder="Amount Tugrug" title="Amount Tugrug" name="amount_tugrug" type="text" value="{{ Input::old('amount_tugrug') }}" disabled="disabled">
            {{ $errors->first('amount_tugrug', '<span class="help-inline">:message</span>') }}
        </div>
    </div>
    <div class="control-group {{ $errors->first('exchange_rate', ' error') }}">
        <label class="control-label">Exchange Rate</label>
        <div class="controls">
            <input id="exchange_rate" class="tugrug" placeholder="Exchange rate" title="Exchange rate" name="exchange_rate" type="text" value="{{ Input::old('exchange_rate') }}" disabled="disabled">
            {{ $errors->first('exchange_rate', '<span class="help-inline">:message</span>') }}
        </div>
    </div>
    <div  class="control-group {{ $errors->first('amount_yen', ' error') }}">
        <label class="control-label" for="amount_yen">Amount Yen</label>
        <div class="controls">
            <input id="amount_yen" class="yen" placeholder="Amount Yen" title="Amount Yen" name="amount_yen" type="text" value="{{ Input::old('amount_yen') }}" disabled="disabled">
            {{ $errors->first('amount_yen', '<span class="help-inline">:message</span>') }}
        </div>
    </div>
    <div  class="control-group {{ $errors->first('amount', ' error') }}">
        <label class="control-label" for="amount">Amount total</label>
        <div class="controls">
            <input id="amount_total" class="" placeholder="Amount total" title="Amount total" name="amount" type="text" value="{{ Input::old('amount') }}">
            {{ $errors->first('amount', '<span class="help-inline">:message</span>') }}
        </div>
    </div>

    <div class="form-actions">
        {{  Form::submit('Submit', array('class' => 'btn btn-info')) }} &nbsp;&nbsp;
        {{  link_to_route('car_balance.money_exchange.index', 'Cancel', null, array('class' => 'btn ')) }}
    </div>
    {{  Form::close() }}
</div>
@stop

@section('pagestyles')
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap/bootstrap.css') }} />
<link rel="stylesheet" type="text/css" href={{ asset('assets/bootstrap-datepicker/datepicker.css') }} />
@stop

@section('pagescripts')
<script type="text/javascript" src={{ asset('assets/bootstrap/bootstrap.js') }}></script>
<script type="text/javascript" src={{ asset('assets/bootstrap-datepicker/datepicker.js') }}></script>
<script type="text/javascript" >
    $(document).ready(function(){
        $(function() {
            $( ".datepicker" ).datepicker({
                defaultDate: "+0d",
                format: "yyyy-mm-dd",
                autoclose: true
            });
        });
        $("input[name='exchange_type']").change(function(e){
        //$("#exchange_type1, #exchange_type2").change(function () {
            if($(this).val() == '1') {
                $('.yen').removeAttr("enabled", "enabled");
                $('.tugrug').removeAttr("disabled", "disabled");
                $('.tugrug').attr("enabled", "enabled");
                $('.yen').attr("disabled", "disabled");
                $("#exchange_rate").each(function(i){
                    $(this).change(function () {
                        $("#amount_total").val(parseInt($("#amount_tugrug").val()/$("#exchange_rate").val()));

                    });
                });
            }
            else if($(this).val() == '2') {
                $('.tugrug').removeAttr("enabled", "enabled");
                $('.yen').removeAttr("disabled", "disabled");
                $('.yen').attr("enabled", "enabled");
                $('.tugrug').attr("disabled", "disabled");
                $("#amount_yen").each(function(i){
                    $(this).change(function () {
                        $("#amount_total").val(parseInt($("#amount_yen").val()));

                    });
                });
            }
        });



    });

</script>
@stop